package com.hyx.api.controller.pc_admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hyx.api.domain.bo.RecycleOrderBo;
import com.hyx.api.domain.vo.RecycleOrderVo;
import com.hyx.api.service.pc_admin.IRecycleOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 回收订单Controller
 *
 * @author ruoyi
 * @date 2023-10-20
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/recycle/order")
public class RecycleOrderController extends BaseController {
    private final IRecycleOrderService recycleOrderService;

    /**
     * 查询回收订单列表
     */
    @PreAuthorize("@ss.hasPermi('recycle:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecycleOrderBo bo) {
        startPage();
        List<RecycleOrderVo> list = recycleOrderService.queryRecycleOrderList(bo);
        return getDataTable(list);
    }

    /**
     * 导出回收订单列表
     */
    @PreAuthorize("@ss.hasPermi('recycle:order:export')")
    @Log(title = "回收订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecycleOrderBo bo) {
        List<RecycleOrderVo> list = recycleOrderService.selectRecycleOrderList(bo);
        ExcelUtil<RecycleOrderVo> util = new ExcelUtil<>(RecycleOrderVo.class);
        util.exportExcel(response, list, "回收订单数据");
    }

    /**
     * 获取回收订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('recycle:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(recycleOrderService.selectRecycleOrderById(id));
    }

    /**
     * 新增回收订单
     */
    @PreAuthorize("@ss.hasPermi('recycle:order:add')")
    @Log(title = "回收订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody RecycleOrderBo bo) {
        return toAjax(recycleOrderService.insertRecycleOrder(bo));
    }

    /**
     * 修改回收订单
     */
    @PreAuthorize("@ss.hasPermi('recycle:order:edit')")
    @Log(title = "回收订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody RecycleOrderBo bo) {
        return toAjax(recycleOrderService.updateRecycleOrder(bo));
    }

    /**
     * 删除回收订单
     */
    @PreAuthorize("@ss.hasPermi('recycle:order:remove')")
    @Log(title = "回收订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(recycleOrderService.deleteRecycleOrderByIds(ids));
    }

    /**
     * 获取回收订单详情
     *
     * @param id
     * @return
     */
    @GetMapping("/queryRecycleOrderDetail")
    public AjaxResult queryRecycleOrderDetail(@RequestParam Long id) {
        return AjaxResult.success(recycleOrderService.queryRecycleOrderDetail(id));
    }
}

